package com.yizooo.tallybook;

import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.yizooo.tallybook.db.DBManager;

public class TallySettingActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tally_setting);
    }
    public void onClick(View view){
        int viewId=view.getId();
        if (viewId==R.id.setting_iv_back){
            finish();
        }else if (viewId==R.id.setting_tv_clear){
            showDeleteDialog();
        }

    }

    private void showDeleteDialog() {
        Log.d("TEST", "Dialog shown");
        try {
            new AlertDialog.Builder(TallySettingActivity.this)
                     .setTitle("删除提示")
                    .setMessage("您确定要删除所有记录吗？\n注意：删除后无法恢复，请慎重选择！")
                    .setNegativeButton("取消",null)
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            DBManager.deleteAllAccount();
                            Toast.makeText(TallySettingActivity.this,"删除成功",Toast.LENGTH_SHORT).show();
                        }
                    })
                    .show();

        }catch (Exception e){
            Log.e("TEST", "弹窗异常: ", e); // 输出错误日志
        }
        }
    }

